<include file="public@header" />
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>

</head>

<body>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:url('AdminOrder/courseList')}">课程列表</a></li>
            <li class="active"><a href="#">录入订单</a></li>
        </ul>
        <form action="{:url('AdminOrder/editOrderSave')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
            <div class="row">
                <div class="col-md-5">
                    <table class="table table-bordered">
                        <tr>
                            <th width="150">课程ID</th>
                            <td>
                                {$data.id}
                            </td>
                        </tr>
                        <tr>
                            <th width="150">课程名称</th>
                            <td>
                                {$data.title}
                            </td>
                        </tr>
                        <tr>
                            <th>班别</th>
                            <td>
                                {$data.school_class.name}
                            </td>
                        </tr>
                        <tr>
                            <th>教师</th>
                            <td>
                                {$data.school_teacher.name}
                            </td>
                        </tr>
                        <tr>
                            <th>课室</th>
                            <td>
                                {$data.classroom}
                            </td>
                        </tr>
                        <tr>
                            <th>班额/已报</th>
                            <td>
                                {$data.num}/{$data.order_count}
                            </td>
                        </tr>
                        <tr>
                            <th>价格</th>
                            <td>
                                {$data.price}
                            </td>
                        </tr>
                        <tr>
                            <th>座位号</th>
                            <td>
                                {$orderData.seat}
                            </td>
                        </tr>
                        <tr>
                            <th>开班时间</th>
                            <td>
                                {$data.open_time}
                            </td>
                        </tr>
                        <tr>
                            <th>报名时间</th>
                            <td>
                                {$data.signup_time}
                            </td>
                        </tr>
                        <tr>
                            <th>上课时间</th>
                            <td>
                                {$data.class_time}
                            </td>
                        </tr>
                        <tr>
                            <th>报名截止时间</th>
                            <td>
                                {$data.cutoff_time}
                            </td>
                        </tr>
                        <tr>
                            <th>报名条件</th>
                            <td>
                                {$data.excerpt}
                            </td>
                        </tr>
                    </table>
                    <hook name="portal_admin_article_edit_view_main" />

                </div>
                <div class="col-md-7">
                    <table class="table table-bordered">
                        <tr>
                            <th>课程（输入需变更课程ID）</th>
                            <td>
                                <input class="form-control" type="text" name="course_id" id="course_id" required
                                    placeholder="请输入课程ID" value="{$orderData.course_id}">
                            </td>
                        </tr>
                        <tr>
                            <th width="150">学员名称</th>
                            <td>
                                <input class="form-control" type="text" name="student_name" id="student_name" required
                                    placeholder="请输入学员名称" value="{$orderData.student_name}">
                            </td>
                        </tr>
                        <tr>
                            <th>家长名称</th>
                            <td>
                                <input class="form-control" type="text" name="parent_name" id="parent_name" required
                                    placeholder="请输入家长名称" value="{$orderData.parent_name}">
                            </td>
                        </tr>
                        <tr>
                            <th>联系电话</th>
                            <td>
                                <input class="form-control" type="text" name="phone" id="phone" required placeholder="请输入联系电话"
                                    value="{$orderData.phone}">
                            </td>
                        </tr>
                        <tr>
                            <th>学校</th>
                            <td>
                                <input class="form-control" type="text" name="current_school" id="current_school"
                                    required placeholder="请输入学校名称" value="{$orderData.current_school}">
                            </td>
                        </tr>
                        <tr>
                            <th>支付方式<span id="post-status-error" style="color: red;display: none"></span></th>
                            <td>
                                <php>
                                    $xj = $orderData['pay_type'] == "现金"? 'checked' : "";
                                    $wx = $orderData['pay_type'] == "微信"? 'checked' : "";
                                    $sm = $orderData['pay_type'] == "扫码"? 'checked' : "";
                                </php>
                                <input type="radio" id="post-status-checkbox" name="pay_type" value="1" {$xj} onclick="chanePay(1)">
                                现金
                                <input type="radio" id="post-status-checkbox" name="pay_type" value="0" {$wx} onclick="chanePay(0)">
                                微信
                                <input type="radio" id="post-status-checkbox" name="pay_type" value="2" {$sm} onclick="chanePay(2)">
                                扫码
                            </td>
                        </tr>
                        <tr id="pays">
                            <th>支付状态<span id="post-status-error" style="color: red;display: none"></span></th>
                            <td>
                                <php>
                                    $wf = $orderData['pay_status'] == "未支付"? 'checked' : "";
                                    $yf = $orderData['pay_status'] == "已支付"? 'checked' : "";
                                    $yt = $orderData['pay_status'] == "已退款"? 'checked' : "";
                                </php>
                                <input type="radio" id="post-status-checkbox" name="pay_status" value="0" {$wf}> 未支付
                                <input type="radio" id="post-status-checkbox" name="pay_status" value="1" {$yf}> 已支付
                                <input type="radio" id="post-status-checkbox" name="pay_status" value="3" {$yt}> 已退款
                            </td>
                        </tr>
                        <tr>
                            <th>座位</th>
                            <td>
                                <input class="form-control" type="text" value="" name="seat" id="seat" readonly />
                                <div class="seats">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th>备注</th>
                            <td>
                                <textarea class="form-control" name="remake" style="height: 50px;" placeholder="请填写备注说明内容">{$orderData.remake}</textarea>
                            </td>
                        </tr>
                    </table>

                    <hook name="portal_admin_article_edit_view_right_sidebar" />
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <input id="id" type="hidden" name="id" value="{$orderData.id}">
                            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('EDIT')}</button>
                            <a class="btn btn-default" href="{:url('AdminOrder/index')}">{:lang('BACK')}</a>
                            <if condition="($orderData['pay_status'] == '已支付') && ($orderData['pay_type'] == '微信') && ($admin_id==1)">                         
                                <a style="margin-left:200px;background-color: red" class="btn btn-default" href="javascript:0" onclick="wx_refund('{$orderData.id}')">微信退款</a>
                            </if>
                        </div>                       
                    </div>
                </div>
            </div>
        </form>
    </div>
    <style>
        .seats{
        margin:0 auto;
        width:400px;  
        margin-top:5px;       
        display: flex;
        flex-direction: row;
        flex-wrap:wrap;
        justify-content:flex-start;  
        overflow: hidden;
        white-space: nowrap;       
    }
    .seats .item{  
        margin-top:5px;
    }
    .seats .seat-item{
        width:40px;
        height:40px;
        margin:1px;
    }
    .m-right{
  margin-right:20px;
}
.selected{
  background-color: #6ce653;
  border-radius: 13px;
}
.disabled{
  background-color: #c5c8ce;
  border-radius: 13px;
}
</style>

    <script type="text/javascript" src="__STATIC__/js/admin.js"></script>
    <script type="text/javascript">
        function doSelectSeat() {
            var selectedCategoriesId = $('#js-categories-id-input').val();

        }

        $(function () {
            
            if ("{$orderData['pay_status']}" == "未支付") {
                $("#pays").hide()
            } else if ("{$orderData['pay_type']}" == "微信") {
                $("#pays").hide()
            }
            $("#seat").val("{$orderData['seat']}")
            var seats = new Array("{$seats}")

            if (seats.length == 1) {
                seats = [{$seats}]
            }

            set_seats(seats, "{$data.num}")
        })

        function set_seats(seats, num) {
            var str = '';
            for (var i = 1; i <= parseInt(num); i++) {
                var cls = '';
                var std = '';
                if (i % 2 == 0 && i % 8 != 0) {
                    cls = "m-right";
                }
                if (seats.indexOf(i) != -1) {
                    std = "disabled";
                }

                str += '<div class="item ' + cls + ' ' + std +
                    '"><img class="seat-item" src="__STATIC__/images/seat.png" width="40" height="40" data-seat="' + i +
                    '" onClick="selectSeat(this)"/></div>'
            }
            $(".seats").append(str);
        }

        function selectSeat(data) {
            var seat = $(data).data("seat");

            if ($("#seat").val()) {
                $('[data-seat="' + $("#seat").val() + '"]').removeClass("selected")
            }
            $(data).addClass("selected")
            $("#seat").val($(data).data("seat"))

        }
        $("#course_id").blur(function () {
            $.ajax({
                url: '/school/admin_order/ajax_getCourseSeats',
                data: {
                    course_id: $('#course_id').val(),
                },
                success: function (data) {
                    $(".seats").html('')
                    $("#seat").val('')
                    set_seats(data.seats, data.num)
                }
            })
        })

        function chanePay(status) {
            if (status == 1 || status==2) {
                $("#pays").show();
            } else if(status == 0){
                $("#pays").hide()
            }
        }

        function wx_refund(id) {
            if (confirm("你确定退款吗？")) {
                $.ajax({
                    url: '/school/admin_order/ajax_pay_refund',
                    data: {
                        id: id,
                    },
                    success: function (data) {
                        data = JSON.parse(data)     
                                         
                        if(data.return_code=="SUCCESS" && data.result_code=="SUCCESS"){
                            alert('退款成功!退款金额：'+ data.cash_refund_fee / 100)
                            window.location.href="/school/admin_order/index";
                        }else{
                            alert('退款失败!原因：'+ data.err_code_des)
                        }
                    }
                })
            }
        }
    </script>
</body>

</html>